package com.bjqh.edu.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Base.GlideRoundTransform;
import com.bjqh.edu.Bean.Headlines;
import com.bjqh.edu.R;
import com.bjqh.edu.UI.Activity.Index.FreeReservationActivity;
import com.bjqh.edu.UI.Utils.XCRoundRectImageView;
import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/26.
 */

public class HeadlinesAdapter extends BaseAdapter {
    private List<Headlines.RowsBean> list;
    private Context ctx;
    private ViewHolder holder;

    public HeadlinesAdapter(Context ctx, List<Headlines.RowsBean> list) {
        this.ctx = ctx;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(ctx).inflate(R.layout.item_headlines, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.title.setText(list.get(i).getTitle());
        holder.tvTime.setText(AppConstants.getltimes(list.get(i).getTime()));


        Glide.with(ctx)
                .load(AppConstants.IMG_URL + list.get(i).getImg())
                .error(R.mipmap.teacher)
                .transform(new GlideRoundTransform(ctx, 5))
                .into(holder.iv);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("url", list.get(i).getContent());
                intent.setClass(ctx, FreeReservationActivity.class);
                ctx.startActivity(intent);
            }
        });

        return view;
    }




    static class ViewHolder {
        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.iv)
        ImageView iv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }



}
